package service

import (
	"time"
	"zimuzu_cvn_web_api/config"
	"zimuzu_cvn_web_api/model"
	. "zimuzu_cvn_web_api/pkg/e"
)

//添加新管理员
//Auth: Xu
func AddAdminUser(mobile , pwd, nickName string) (user model.User, err error) {
	if nickName == "" {
		nickName = mobile
	}

	var createUser model.AdminUserDb
	createUser.Account = mobile
	createUser.NickName = nickName
	createUser.CreateTime = time.Now().Unix()
	createUser.Salt = GetRandomStr(6)
	createUser.Pwd = CreatePassword(pwd, createUser.Salt)

	_, err = model.CreateAdminUser(config.C.DB.DB,createUser)
	if err != nil {
		return
	}

	return user, nil
}

//查询管理员信息
//Auth:Xu
func GetAdminUserByUid(uid int64)(model.AdminUserDb, error){
	return model.GetAdminUserByUid(config.C.DB.DB,uid)
}

//管理员列表
//Auth:Xu
func AdminList()(res []model.AdminUserList, err error){
	res ,err = model.GetAdminList()

	return
}


//删除管理员
//Auth:Xu
func DeleteAdminUser(adminId int64)( err error){
	err = model.DeleteAdminUser(config.C.DB.DB, adminId)

	return
}